package com.taokatao.cardmee.business.carddetail;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taokatao.cardmee.R;
import com.taokatao.cardmee.WebActivity;
import com.taokatao.cardmee.api.model.CardDetailInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardDetailADLayout1 extends LinearLayout implements View.OnClickListener {

    @BindView(R.id.i_ad_cover) ImageView iAdCover;
    @BindView(R.id.t_ad_title) TextView tAdTitle;
    CardDetailInfo.AD mAD;

    public CardDetailADLayout1(Context context) {
        this(context, null);
    }

    public CardDetailADLayout1(Context context, AttributeSet attrs) {
        super(context, attrs);
        ButterKnife.bind(this, LayoutInflater.from(context).inflate(R.layout.layout_card_detail_ad_1, this));
        setOnClickListener(this);
    }

    public void setData(CardDetailInfo.AD ad) {
        if (ad == null) return;
        mAD = ad;
        Glide.with(getContext()).load(mAD.adCover).placeholder(R.mipmap.card_fd_course_default).into(iAdCover);
        tAdTitle.setText(mAD.adTitle);
    }

    @Override
    public void onClick(View v) {
        if (mAD != null) {
            if(!TextUtils.isEmpty(mAD.adUrl)) {
                Intent intent = new Intent(v.getContext(), WebActivity.class);
                intent.putExtra("extra_url", mAD.adUrl);
                v.getContext().startActivity(intent);
            }
        }
    }
}
